<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.4/socket.io.js"></script>
    <script>
        var socket = io('http://localhost:8003');
        socket.on('connect', function () {
            console.log('connect');
            socket.emit('test', 'hahah');
            socket.emit('test', {msg: 'hahah'});
            socket.send({msg: 'send'});
            setTimeout(function () {
                console.log('send msg');
                socket.emit('test', 'something...');
            }, 2000);
        });

        //namespace
        var ns = io('http://localhost:8003/ns');
        ns.on('connect', function () {
            console.log('connect ns');
        });

        var ns1 = io.connect('http://localhost:8003/ns1');
        var ns2 = io.connect('http://localhost:8003/ns2');
        ns1.on('connect', function () {
            ns1.emit('test', 'hahah ns1');
            console.log('connect ns 1');
        });
        ns2.on('connect', function () {
            ns2.emit('test', 'hahah ns2');
            console.log('connect ns 2');
        });

        ns2.on('receive', function (data) {
            console.log('ns2', 'receive', data);
        });

        ns2.on('room', function (data) {
            console.log('ns2', 'room', data);
        });

        //room
        var roomNS1 = io('http://localhost:8003/roomNS');
        var roomNS2 = io('http://localhost:8003/roomNS');
        var roomNS3 = io('http://localhost:8003/roomNS');

        roomNS1.on('connect', function () {
            roomNS1.emit('join', 'room1');
        });

        roomNS2.on('connect', function () {
            roomNS2.emit('join', 'room2');
        });

        roomNS3.on('connect', function () {
            roomNS3.emit('join', 'room2');
        });

        roomNS1.on('msg', function (msg) {
            console.log('roomNS1', msg);
        });

        roomNS2.on('msg', function (msg) {
            console.log('roomNS2', msg);
        });

        roomNS3.on('msg', function (msg) {
            console.log('roomNS3', msg);
        });

    </script>
</head>
<body>

</body>
</html>